﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataImport.aspx.cs" Inherits="InformationSystem.WebSite.UtilityPage.DataImport" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .cbStates-list
        {
            width: 298px;
            font: 12px tahoma,arial,helvetica,sans-serif;
        }
        .cbStates-list2
        {
            width: 470px;
            font: 12px tahoma,arial,helvetica,sans-serif;
        }
        .cbStates-list th
        {
            font-weight: bold;
        }
        
        .cbStates-list td, .cbStates-list th
        {
            padding: 3px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server">
    </ext:ResourceManager>
    <ext:Panel ID="WizardPanel" runat="server" Title="数据导入向导" Padding="15" Height="315"
        Layout="card" ActiveIndex="0">
        <Items>
            <ext:FormPanel runat="server" ID="BasicForm" Header="false" PaddingSummary="10px 10px 0 10px"
                MonitorValid="true" LabelWidth="30">
                <Defaults>
                    <ext:Parameter Name="anchor" Value="95%" Mode="Value">
                    </ext:Parameter>
                    <ext:Parameter Name="allowBlank" Value="false" Mode="Raw" />
                </Defaults>
                <Items>
                    <ext:Label ID="Label3" runat="server">
                        <Content>
                            <p style="font-size: 20px;">
                                欢迎使用数据导入向导</p>
                            <p style="font-size: 13px; margin-top: 10px; margin-bottom: 10px">
                                1.请选择导入类型</p>
                        </Content>
                    </ext:Label>
                    <ext:ComboBox runat="server" SelectedIndex="0" Editable="false">
                        <Items>
                            <ext:ListItem Text="学生信息导入" Value="0" />
                            <ext:ListItem Text="学生成绩导入" Value="1" />
                        </Items>
                    </ext:ComboBox>
                    <ext:Label ID="Label1" runat="server">
                        <Content>
                            <p style="font-size: 13px; margin-top: 10px; margin-bottom: 10px">
                                2.请选择需要导入的Excel文件(目前仅支持*.xls)</p>
                        </Content>
                    </ext:Label>
                    <ext:FileUploadField runat="server" ID="fileUpLoad" Icon="Attach" ButtonText="浏览...">
                    </ext:FileUploadField>
                    <ext:CompositeField runat="server">
                        <Items>
                            <ext:HyperLink runat="server" Text="学生信息模板"  Icon="DiskDownload">
                            </ext:HyperLink>
                            <ext:HyperLink ID="HyperLink1" runat="server" Text="学生成绩模板" Icon="DiskDownload">
                            </ext:HyperLink>
                        </Items>
                    </ext:CompositeField>
                </Items>
                <Listeners>
                    <ClientValidation Handler="#{SaveButton}.setDisabled(!valid);" />
                </Listeners>
                <Buttons>
                    <ext:Button ID="SaveButton" runat="server" Text="上传">
                        <DirectEvents>
                            <Click OnEvent="UploadClick" Before="if (!#{BasicForm}.getForm().isValid()) { return false; } 
                                Ext.Msg.wait('正在上传文件，请稍后...', '上传');" Failure="Ext.Msg.show({ 
                                title   : '错误', 
                                msg     : '上传错误，请重试！', 
                                minWidth: 200, 
                                modal   : true, 
                                icon    : Ext.Msg.ERROR, 
                                buttons : Ext.Msg.OK 
                            });">
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                    <ext:Button runat="server" Text="清空">
                        <Listeners>
                            <Click Handler="#{BasicForm}.getForm().reset();" />
                        </Listeners>
                    </ext:Button>
                </Buttons>
            </ext:FormPanel>
            <ext:FormPanel runat="server" ID="SQLTableSelectForm" Header="false" PaddingSummary="10px 10px 0 10px"
                MonitorValid="true" LabelWidth="30">
                <Defaults>
                    <ext:Parameter Name="anchor" Value="95%" Mode="Value">
                    </ext:Parameter>
                    <ext:Parameter Name="allowBlank" Value="false" Mode="Raw" />
                </Defaults>
                <Items>
                    <ext:Label ID="Label2" runat="server">
                        <Content>
                            <p style="font-size: 20px;">
                                欢迎使用数据导入向导</p>
                            <p style="font-size: 13px; margin-top: 10px; margin-bottom: 10px">
                                请选择目标数据库表格</p>
                        </Content>
                    </ext:Label>
                    <ext:ComboBox runat="server" ID="DestCmb" TypeAhead="true" ForceSelection="true"
                        DisplayField="TableName" ValueField="TableDesp" PageSize="20" ItemSelector="tr.list-item"
                        MinChars="1" ListWidth="470" Width="470">
                        <Store>
                            <ext:Store ID="DestCmbStore" runat="server" OnRefreshData="DestCmb_Refresh">
                                <Reader>
                                    <ext:ArrayReader>
                                        <Fields>
                                            <ext:RecordField Name="TableName" Type="String">
                                            </ext:RecordField>
                                            <ext:RecordField Name="TableDesp" Type="String">
                                            </ext:RecordField>
                                        </Fields>
                                    </ext:ArrayReader>
                                </Reader>
                            </ext:Store>
                        </Store>
                        <Template ID="Template2" runat="server">
                            <Html>
                                <tpl for=".">
						            <tpl if="[xindex] == 1">
							            <table class="cbStates-list2">
								            <tr>
									            <th>表格名称</th>
                                                <th>描述</th>
								            </tr>
						            </tpl>
						            <tr class="list-item">
							            <td style="padding:3px 0px;">{TableName}</td>
							            <td  style="padding:3px 0px;">{TableDesp}</td>
						            </tr>
						            <tpl if="[xcount-xindex]==0">
							            </table>
						            </tpl>
					            </tpl>
                            </Html>
                        </Template>
                        <Triggers>
                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                        </Triggers>
                        <Listeners>
                            <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                            <TriggerClick Handler="if (index == 0) { this.focus().clearValue(); trigger.hide();}" />
                            <Select Handler="this.triggers[0].show();" />
                        </Listeners>
                    </ext:ComboBox>
                </Items>
            </ext:FormPanel>
            <ext:Panel ID="MatchPanel" runat="server" Border="false" Header="false">
                <Items>
                    <ext:GridPanel ID="MatchGrid" runat="server">
                        <Store>
                            <ext:Store runat="server" ID="GridStore">
                                <Reader>
                                    <ext:ArrayReader>
                                        <Fields>
                                            <ext:RecordField Name="ExcelColumnID" Type="String">
                                            </ext:RecordField>
                                            <ext:RecordField Name="ExcelColumnType" Type="String">
                                            </ext:RecordField>
                                            <ext:RecordField Name="SQLColumn" Type="String">
                                            </ext:RecordField>
                                        </Fields>
                                    </ext:ArrayReader>
                                </Reader>
                            </ext:Store>
                        </Store>
                        <Listeners>
                        </Listeners>
                        <ColumnModel runat="server">
                            <Columns>
                                <ext:Column Header="Excel字段" DataIndex="ExcelColumnID" Width="120">
                                </ext:Column>
                                <ext:Column Header="Excel字段类型" DataIndex="ExcelColumnType" Width="120">
                                </ext:Column>
                                <ext:Column Header="目标字段" DataIndex="SQLColumn" Width="200">
                                    <Editor>
                                        <ext:ComboBox runat="server" ID="cbSource" TypeAhead="true" ForceSelection="true"
                                            DisplayField="SqlFiledDescp" ValueField="SqlFieldName" PageSize="20" ItemSelector="tr.list-item"
                                            MinChars="1" ListWidth="300">
                                            <Store>
                                                <ext:Store ID="cbmStore" runat="server" OnRefreshData="cmbData_Refresh">
                                                    <Reader>
                                                        <ext:ArrayReader>
                                                            <Fields>
                                                                <ext:RecordField Name="SqlFieldName" Type="String">
                                                                </ext:RecordField>
                                                                <ext:RecordField Name="SqlFieldType" Type="String">
                                                                </ext:RecordField>
                                                                <ext:RecordField Name="SqlFiledDescp" Type="String">
                                                                </ext:RecordField>
                                                            </Fields>
                                                        </ext:ArrayReader>
                                                    </Reader>
                                                </ext:Store>
                                            </Store>
                                            <Template ID="Template1" runat="server">
                                                <Html>
                                                    <tpl for=".">
						                                <tpl if="[xindex] == 1">
							                                <table class="cbStates-list">
								                                <tr>
									                                <th>目标字段</th>
									                                <th>类型</th>
                                                                    <th>描述</th>
								                                </tr>
						                                </tpl>
						                                <tr class="list-item">
							                                <td style="padding:3px 0px;">{SqlFieldName}</td>
							                                <td  style="padding:3px 0px;">{SqlFieldType}</td>
                                                            <td  style="padding:3px 0px;">{SqlFiledDescp}</td>
						                                </tr>
						                                <tpl if="[xcount-xindex]==0">
							                                </table>
						                                </tpl>
					                                </tpl>
                                                </Html>
                                            </Template>
                                            <Triggers>
                                                <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                            </Triggers>
                                            <Listeners>
                                                <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                                <TriggerClick Handler="if (index == 0) { this.focus().clearValue(); trigger.hide();}" />
                                                <Select Handler="this.triggers[0].show();" />
                                            </Listeners>
                                        </ext:ComboBox>
                                    </Editor>
                                </ext:Column>
                            </Columns>
                        </ColumnModel>
                        <SelectionModel>
                            <ext:RowSelectionModel runat="server" SingleSelect="true" />
                        </SelectionModel>
                    </ext:GridPanel>
                </Items>
            </ext:Panel>
            <ext:FormPanel runat="server" ID="LastForm" Header="false" PaddingSummary="10px 10px 0 10px"
                MonitorValid="true" LabelWidth="30">
                <Defaults>
                    <ext:Parameter Name="anchor" Value="95%" Mode="Value">
                    </ext:Parameter>
                    <ext:Parameter Name="allowBlank" Value="false" Mode="Raw" />
                </Defaults>
                <Items>
                    <ext:Label ID="Label1l" runat="server">
                        <Content>
                            <p style="font-size: 20px;">
                                欢迎使用数据导入向导</p>
                            <p style="font-size: 15px; margin-top: 10px; margin-bottom: 10px">
                                信息确认</p>
                            <p style="font-size: 13px; margin-top: 10px; margin-bottom: 10px">
                                Excel中数据即将被导入到数据库 xx 表中，将更新并追加新纪录到目标中。</p>
                            <p style="font-size: 14px; margin-top: 10px; margin-bottom: 10px">
                                点击导入按钮开始导入。</p>
                        </Content>
                    </ext:Label>
                </Items>
                <Buttons>
                    <ext:Button runat="server" Text="导入" ID="btnImport">
                        <DirectEvents>
                            <Click OnEvent="btnImport_Click">
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:FormPanel>
        </Items>
        <Buttons>
            <ext:Button ID="btnPrev" Hidden="true" runat="server" Text="上一步" Disabled="true"
                Icon="PreviousGreen">
                <DirectEvents>
                    <Click OnEvent="Prev_Click">
                        <ExtraParams>
                            <ext:Parameter Name="index" Value="#{WizardPanel}.items.indexOf(#{WizardPanel}.layout.activeItem)"
                                Mode="Raw" />
                        </ExtraParams>
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:Button ID="btnNext" Hidden="true" runat="server" Text="下一步" Disabled="true"
                Icon="NextGreen">
                <DirectEvents>
                    <Click OnEvent="Next_Click">
                        <ExtraParams>
                            <ext:Parameter Name="index" Value="#{WizardPanel}.items.indexOf(#{WizardPanel}.layout.activeItem)"
                                Mode="Raw" />
                        </ExtraParams>
                    </Click>
                </DirectEvents>
            </ext:Button>
        </Buttons>
    </ext:Panel>
    </form>
</body>
</html>
